package com.HomeWorkhsp.Chapter07;
import java.util.*;
/**
 * Enjoy programming!!!
 * Time: 2021/11/11 -  13:31
 */
public class Test13 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        Tom t = new Tom();
        int isWinCount = 0;
        int[][] arr1 = new int[3][3];

        String[] arr2 = new String[3];
        int j = 0;
        for (int i = 0; i < 3; i++){
            System.out.print("请输入你出(0-石头；1-剪刀；2-布)：");
            int num = in.nextInt();
            t.setTomGuessNum(num);
            int tomGuess = t.getTomGuessNum();
            arr1[i][j + 1] = tomGuess;

            int comGuess = t.computerNum();
            arr1[i][j + 2] = comGuess;

            String iswin = t.vsComputer();
            arr2[i] = iswin;
            arr1[i][j] = t.count;

            System.out.println("=========================");
            System.out.println("局数\t玩家的出拳\t电脑的出拳\t输赢情况");
            System.out.println(t.count + "\t\t" + tomGuess + "\t\t\t" + comGuess + "\t\t\t" + t.vsComputer());
            System.out.println("=========================");
            System.out.println("\n\n");
            isWinCount = t.winCount(iswin);
        }

        System.out.println("局数\t玩家的出拳\t电脑的出拳\t输赢情况");
        int i = 0;
        for (int[] r : arr1){
            for (int e : r){
                System.out.print(e + "\t\t\t");

            }

            System.out.println(arr2[i]);
            i++;
        }
        System.out.println("你赢了" + isWinCount + "次");

    }
}
class Tom{
    int tomGuessNum;
    int comGuessNum;
    int winCountNum;
    int count = 1;

    public int computerNum(){
        return comGuessNum = (int)(Math.random()*3);
    }
    public void setTomGuessNum(int tomGuessNum){
        if (tomGuessNum < 0 || tomGuessNum > 2){
//            throw new IllegalAccessException("数字输入错误");
        }
        this.tomGuessNum = tomGuessNum;
    }
    public int getTomGuessNum(){
        return tomGuessNum;
    }

    public String vsComputer(){
        if (tomGuessNum == 0 && comGuessNum == 1){
            return "你赢了";
        }
        else if (tomGuessNum == 1 && comGuessNum == 2){
            return "你赢了";
        }
        else if (tomGuessNum == 2 && comGuessNum == 0){
            return "你赢了";
        }
        else if (tomGuessNum == comGuessNum){
            return "平局";
        }
        else{
            return "你输了";
        }
    }
    public int winCount(String s){
        count++;
        if (s == "你赢了"){
            winCountNum++;
        }
        return winCountNum;
    }
}
